package cn.hesion.nio;
/**
 * ClassName: NIOFileChannel03 <br/>
 * Description: <br/>
 * date: 2021/1/22 11:12<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.nio.ByteBuffer;

/**
 * @program: NettyLearn
 * @description: 演示不同类型的buffer
 * @author: hesion
 * @create: 2021-01-22 11:12
 **/
public class NIOFileChannel03 {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(64);

        //按顺序存入，也需要按顺序读取,否则会报BufferUnderflowException
        byteBuffer.putChar('尚');
        byteBuffer.putDouble(0.01);
        byteBuffer.putInt(1);

        //切换buffer 读写状态
        byteBuffer.flip();

        //存怎么存，取怎么取
        System.out.println(byteBuffer.getChar());
        System.out.println(byteBuffer.getDouble());
        System.out.println(byteBuffer.getInt());
        System.out.println(byteBuffer.getDouble());
    }
}
